<!-- subpkg_consult/department/index.vue -->
<script lang="ts" setup>
import { departmentListApi } from '@/apis/consult';
import type { DepartData, DepartItem } from '@/types/consult';
import { computed } from 'vue';
import { ref } from 'vue';

defineProps<{
  type: string
  illnessType: string
}>()


// 1. 调用接口获取科室数据
const departmentList = ref<DepartData[]>([])
const getDepartment = async () => {
  const res = await departmentListApi()
  departmentList.value = res
  // console.log(res)
}
getDepartment()

// 2. 一级科室切换
const currenIndex = ref(0)
const changeIndex = (index: number) => {
  currenIndex.value = index
}

// 3. 二级科室
// ? 是一定要加
const childList = computed(() => {
  return departmentList.value[currenIndex.value]?.child
})

</script>

<template>
  <view class="department-page">
    <scroll-view scroll-y class="department-primary">
      <view v-for="(item, index) in departmentList" :key="item.id" class="department-item"
        :class="{ active: index === currenIndex }" @click="changeIndex(index)">{{ item.name }}</view>
    </scroll-view>
    <scroll-view class="department-secondary">
      <navigator v-for="child in childList" :key="child.id" hover-class="none"
        :url="`/subpkg_consult/description/index?type=${type}&illnessType=${illnessType}&depId=${child.id}`"
        class="department-item">
        {{ child.name }}
      </navigator>
    </scroll-view>
  </view>
</template>

<style lang="scss">
@import './index.scss';
</style>